package JDBC;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * 执行DQL语句
 */
public class JDBCDemo5 {
    public static void main(String[] args) {
        //需求：查询teacher表中id，name，salary，title字段信息
        try (Connection connection = DBUtil.getConnection()){
            Statement statement = connection.createStatement();
            String sql = "SELECT id,name,salary,title FROM teacher";
            ResultSet results = statement.executeQuery(sql);
            while (results.next()){
//                int id = results.getInt("id");
//                String name = results.getString("name");
//                double salary = results.getDouble("salary");
//                String title = results.getString("title");
                int id = results.getInt(1);
                String name = results.getString(2);
                double salary = results.getDouble(3);
                String title = results.getString(4);
                System.out.println(id+","+name+","+salary+","+title);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
